1403. 非递增顺序的最小子序列
为保证权益,题目请参考 1403. 非递增顺序的最小子序列(From LeetCode).
解决方案1
Python
python
# 1403. 非递增顺序的最小子序列
# https://leetcode.cn/problems/minimum-subsequence-in-non-increasing-order/
from typing import List
class Solution:
def minSubsequence(self, nums: List[int]) -> List[int]:
nums.sort(reverse=True)
s = sum(nums)
ns = 0
ans = []
for i, n in enumerate(nums):
ans.append(n)
ns += n
if ns > s - ns:
break
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19